package com.example.deal.config;

import javax.servlet.Servlet;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

/**
 * SpringCould 2.0+需要为HystrixMricsStreamServlet手动注入到ServletRegistrationBean中
 * 
 * @author Dustyone 初始化一些容器
 *
 */
@Component
public class InitiServlets {
	
	/**
	 * 初始化Hystrix 容器
	 * @return
	 */
	@Bean
	public ServletRegistrationBean<Servlet> getHystrixSerlvet() {
		// HystrixStreamServlet
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();

		ServletRegistrationBean<Servlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/hystrix.stream");
		registrationBean.setName("HystrixMricsStreamServlet");
		return registrationBean;
	}
	
	/**
	 * 初始化turbine容器
	 * @return
	 */
	/*@Bean
	public ServletRegistrationBean<Servlet> getTurbineSerlvet() {
		// TurbineStreamServlet
		TurbineStreamServlet turbineStreamServlet = new TurbineStreamServlet();
		ServletRegistrationBean<Servlet> registrationBean = new ServletRegistrationBean<>(turbineStreamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/turbine.stream");
		registrationBean.setName("TurbineStreamServlet");
		return registrationBean;
	}*/
}